const app = getApp();

Component({

  options: {
    multipleSlots: true,
  },

  data: {
    // 状态栏高度
    statusBarHeight: app.globalData.statusBarHeight,
    // 弹窗的内容
    title: '',
    // 产品名称
    content: '',
    // 是否显示地址
    needAddress: true,
    // 是否显示无法取消提醒
    needCancel:true,
    // 地址
    address: '',
    // 弹窗的关闭按钮文字
    cancelButtonText: '取消',
    // 弹窗的确认按钮文字
    confirmButtonText: '确认',
    // 关闭后执行
    onCancel: null,
    // 确认后执行
    onConfirm: null,
    // 是否隐藏
    isHide: true,
  },

  methods: {
    hide() {
      this.setData({
        isHide: true,
      });
    },
    show(options) {
      if (options.title) {
        this.setData({
          title: options.title,
        });
      }
      if (options.content) {
        this.setData({
          content: options.content,
        });
      }
      if (options.needAddress === false) {
        this.setData({
          needAddress: false,
        });
      }
      else{
        this.setData({
          needAddress: true,
        });
      }
      if (options.needCancel === false) {
        this.setData({
          needCancel: false,
        });
      }
      else{
        this.setData({
          needCancel: true,
        });
      }
      if (options.address) {
        this.setData({
          address: options.address,
        });
      }
      if (options.cancelButtonText) {
        this.setData({
          cancelButtonText: options.cancelButtonText,
        });
      }
      if (options.confirmButtonText) {
        this.setData({
          confirmButtonText: options.confirmButtonText,
        });
      }
      if (options.onCancel) {
        this.setData({
          onCancel: options.onCancel,
        });
      }
      if (options.onConfirm) {
        this.setData({
          onConfirm: options.onConfirm,
        });
      }
      this.setData({
        isHide: false,
      });
    },
    onCancelTap(event) {
      this.setData({
        isHide: true,
      });
      typeof this.data.onCancel == "function" && this.data.onCancel();
    },
    onConfirmTap(event) {
      this.setData({
        isHide: true,
      });
      typeof this.data.onConfirm == "function" && this.data.onConfirm(this.data.content);
    },
  },

})